package com.hx.zhg.web.startup;

import com.app.sicwvbiaalg.SicWvBiaAlgInInfJClass;
import com.app.sicwvbiaalg.SicWvBiaAlgJCLinker;
import com.app.sicwvbiaalg.SicWvBiaAlgOutInfJClass;
import com.hx.zhg.service.system.WxSystemService;
import com.hx.zhg.service.utils.SpringUtil;
import com.hx.zhg.util.FileUtilExt;
import com.hx.zhg.util.LibUtil;
import org.apache.log4j.Logger;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 项目启动时执行类
 *
 * @author zhenghegong
 * @create 2018/3/23 上午10:35
 * @desc
 **/
@Component
public class StartRunner implements ApplicationRunner {

    private static final Logger log = Logger.getLogger(StartRunner.class);

    @Override
    public void run(ApplicationArguments args) throws Exception {
        initAccessToken();
        loadLib();
    }

    /**
     * 初始化ACCESS_TOKEN
     *
     * @throws Exception
     */
    public void initAccessToken() throws Exception {
        WxSystemService wxSystemService = SpringUtil.getBean("wxSystemService");
        wxSystemService.flushAccessToken();
    }

    /**
     * 加载动态连接库
     *
     * @throws Exception
     */
    public void loadLib() throws Exception {
        FileUtilExt.loadCopyResources("native/*");
        LibUtil.setDefaultJavaLibraryPath("native");
        System.loadLibrary("TmlWvBiaAlgAC4001");
    }
}
